<?php
/**
 * Ajax操作类
 * @author yaoli<yaoli@pateo.com.cn>
 * @version 1.0 GetUser add by yaoli<yaoli@pateo.com.cn> 
 */
class arithmetic extends ActionBase {
	
	private $date = null;
	
	function init() {
	
	}
	
	/**
	 * 动作
	 *
	 * @see AActionBase::action()
	 */
	public function action() {
		dump(bin2hex('中华 '));
		dump(bin2hex('种花'));
		
		$test_array = array (12, 5, 10, 9, 100, - 10 );
		$listarray = array ();
		$sort_array = $this->testsort ( $test_array, 2, 0, 5 );
		
		dump($sort_array);
		
	}
	

	
	
	 
	function testsort($array, $index, $begin, $end) {
		global $listarray;
		$listarray = $array;
		if ($begin < $end) {
			$index = $this->quicksort2 ( $listarray, $index, $begin, $end );
			echo 'left<br>';
			$this->testsort ( $listarray, 0, $begin, $index - 1 );
			echo 'right<br>';
			$this->testsort ( $listarray, $index + 1, $index + 1, $end );
		}
		return $listarray;
	}
	
	//快速排序（快速检索为数组第一个）
	function quicksort1($array, $begin, $end) {
		//echo '<br>输入';
		//print_r($array);
		global $listarray;
		$compare = $array [$begin];
		while ( $begin < $end ) {
			while ( $begin < $end && $array [$end] >= $compare )
				$end --;
			$array [$begin] = $array [$end];
			while ( $begin < $end && $array [$begin] <= $compare )
				$begin ++;
			$array [$end] = $array [$begin];
		}
		$array [$begin] = $compare;
		//echo '<br>输出';
		//print_r($array);
		$listarray = $array;
		return $begin;
	}
	 
	 
	//快速排序（检索样本为数组第f_index个）
	function quicksort2($array, $f_index, $begin, $end) {
		global $listarray;
		$compare = $array [$f_index];
		while ( $begin < $end ) {
			while ( $begin < $end && $array [$end] >= $compare )
				$end --;
			$array [$f_index] = $array [$end];
			$f_index = $end;
			while ( $begin < $end && $array [$begin] <= $compare )
				$begin ++;
			$array [$f_index] = $array [$begin];
			$f_index = $begin;
		}
		$array [$f_index] = $compare;
		$listarray = $array;
		return $f_index;
	}
	

}